package com.echo.week.demo;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.echo.week.demo.eneity.Chater;
import com.echo.week.demo.eneity.Operator;
import com.echo.week.demo.eneity.Person;

import java.lang.reflect.Field;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author echo
 * @Description
 * @Date 2023/11/4.
 * @Version 1.0
 */
public class DemoTest {

    public static void main(String[] args) throws IllegalAccessException, ClassNotFoundException {
//        String str = "<msg tp=\"813\" tm=\"1699320117781\" fid=\"u1494998440\" chatMsgId=\"1698896936949_1699320116834_894\">dfasdfasd山豆根发射点功夫是</msg>";
//        String replacementFid = "newFidValue";
//        String regex = "(fid=\")([^\"]*)(\")";
//
//        String result = str.replaceFirst(regex, "$1" + replacementFid + "$3");
//        StringBuilder sb = new StringBuilder(" tp=\"813\" tm=\"1699325908496\" fid=\"u1494998440\" chatMsgId=\"1698896936949_1699325908190_679");
//        String s = sb.toString().replaceFirst(regex, "$1" + replacementFid + "$3");
//        System.out.println(s);
//
//        Operator operator = new Operator();
//        operator.setCity("四川");
//        operator.setOpId("11");
//        String jsonString = JSONObject.toJSONString(operator);
//        Person o = (Person)JSONObject.parseObject(jsonString, Class.forName(operator.getClassName()));
//        System.out.println(o.toString());
//        Map<String, List<String>> map = new HashMap<>();
//        List<String> list = new ArrayList<>();
//        list.add("1");
//        map.put("a",list);
//        List<String> l = map.get("a");
//        l.add("2");
//        System.out.println(JSONObject.toJSONString(map));

        String str = "abc_c_1";
        String[] s = str.split("_", 2);
        System.out.println(JSONObject.toJSONString(s));
    }


    private static  <T> void jsonToClass(JSONObject json,T t) throws IllegalAccessException {
        Field[] fields = t.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            String key = field.getName();
            Class<?> type = field.getType();
            if (type.isAssignableFrom(String.class)){
                field.set(t,json.get(key));
            }else {
                field.set(t,JSONObject.parseObject(json.getString(key),type));
            }
        }
    }
    public static boolean isNullOrLengthZero(String arg) {
        if (arg == null || arg.trim().length() == 0) {
            return true;
        }
        return false;
    }
}
